var express = require('express');
var bodyParser = require('body-parser');
var sign = require('./sign.js');

exports.list = function(req,res){
	var data=sign.delEmptyValue(req.body);

	if(data.andor){
		if(data['protocol[]']){
			data.protocol=data['protocol[]'][0];
			delete data['protocol[]'];

		}
		if(data['businessname[]']){
			data.businessname=data['businessname[]'][0];
			delete data['businessname[]'];
		}
		if(data['parsektv[]']){
			data.parsektv=data['parsektv[]'][0];
			delete data['parsektv[]'];
		}
	}
	sign.dataReq(req,data,req.session.apikey,'/sysmanage/device/list','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}
exports.getBusinessList = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/getbusinesslist','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
} 
exports.businesslist= function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/businesslist','post',function(ResData){
		res.send(ResData);
	})
}


exports.getNetwayList = function(req,res){
	
	sign.nullDataReq(req,req.session.apikey,'/sysmanage/device/getnetwaylist','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
} 

// exports.getCommunicationProtocolList = function(req,res){
// 	sign.nullDataReq(req,req.session.apikey,'/sysmanage/device/getcommunicationprotocollist','post',function(ResData){
// 		if(ResData!=''){
// 			res.send(ResData);
// 		}
// 	})
// }
exports.getDeviceInfo = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/getDevice','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})

}
exports.edit= function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/edit','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})

}
exports.del= function(req,res){
	var data=req.body;
	if(req.body['ids[]'].constructor==String){
       data = {'ids':[req.body['ids[]']]} ;
	}else{
		data = {'ids':req.body['ids[]']} ;
	}
	var val= req.body['ids[]'];
	sign.dataReq(req,data,req.session.apikey,'/sysmanage/device/del','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})

}
exports.datalist = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/dataList','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}
exports.getKtvListBySn = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/getKtvListBySn','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}

exports.getchartdata = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/getchartdata','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}

exports.logList = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/logList','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}

exports.configList = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/configList','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}
exports.protocollist = function(req,res){
	sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/device/protocollist','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}
exports.sendconfig = function(req,res){
	var data=req.body
	if(data.id1 && data.id2){
		data['ktvdata']=[{'id':data.id1,'k':data.k1,'v':data.v1},{'id':data.id2,'k':data.k2,'v':data.v2}]
		delete data["id1"]; 
		delete data["k1"]; 
		delete data["v1"]; 
		delete data["id2"];
		delete data["k2"]; 
		delete data["v2"];
		delete data["configurationType1"];
		
	}else{
		data['ktvdata']=[{'id':data.id1,'k':data.k1,'v':data.v1}]
		delete data["id1"]; 
		delete data["k1"]; 
		delete data["v1"]; 
		delete data["id2"];
		delete data["k2"]; 
		delete data["v2"];
		delete data["configurationType1"];
	}
	sign.dataReq(req,data,req.session.apikey,'/sysmanage/device/sendconfig','post',function(ResData){
		if(ResData!=''){
			res.send(ResData);
		}
	})
}



